home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / CDTools / Players / HippoPlayer / Scopes / HiPScope.c < prev    next >
C/C++ Source or Header  |  1995-10-10  |  5KB  |  190 lines

  1. #include <proto/exec.h>
  2. #include <exec/ports.h>
  3. #include <exec/memory.h>
  4.  
  5. #include <proto/dos.h>
  6.  
  7. #include <proto/intuition.h>
  8. #include <intuition/intuition.h>
  9.  
  10. #include <proto/graphics.h>
  11. #include <graphics/gfx.h>
  12.  
  13. #include "HiPScope.h"
  14.  
  15. struct Window *win;
  16. struct IntuiMessage *imsg;
  17. ULONG class;
  18. UWORD code;
  19.  
  20. struct HippoPort *hport;
  21. struct BitMap    bmap;
  22. UBYTE  *plane1;
  23. UBYTE  *plane2;
  24. UBYTE  *tmp;
  25.  
  26. int ForbitCount = 0;
  27. BOOL Going = TRUE;
  28.  
  29. void ForbidMT(void)
  30. {
  31.   Forbid();
  32.   ForbitCount += 1;
  33. }
  34.  
  35. void PermitMT(void)
  36. {
  37.   if (ForbitCount > 0)
  38.   {
  39.     Permit();
  40.     ForbitCount -= 1;
  41.   }
  42. }
  43.  
  44. BOOL DrawScope(struct PTch *ch, UBYTE *bpl, UWORD xpos, UWORD width, UWORD height)
  45. {
  46.   UWORD  xp;
  47.   UWORD  sp;    // sample pos
  48.   WORD   sl;    // bytes left until end of sample ("channel length")
  49.   BYTE  *sa;    // sample adr
  50.   WORD   vol;
  51.   
  52.   /* Calculate volume for current sample data */
  53.   vol = (ch->volume * hport->mainvolume) >> 6;
  54.   
  55.   /* Skip this channel if there is no sample data */
  56.   if (ch->length < 2) return(FALSE);
  57.   
  58.   sa = (BYTE *)ch->start;
  59.   sl = ch->length << 1;
  60.   sp = 0;
  61.   
  62.   for (xp = xpos ; xp < (xpos + width) ; xp++)
  63.   {
  64.     /* The line below plots a point in bpl buffer. This should be replaced
  65.      * by an assembler routine!
  66.      */
  67.     bpl[(((sa[sp] * vol * height) / (64 * 128)) + 32) * 40 + (xp >> 3)] |= 1 << ((xp & 0x0007) ^ 0x7);
  68.     sp++;
  69.     if (0 == sl--)
  70.     {
  71.       /* If zero bytes left then get sample repeat info */
  72.       if (ch->replen < 2) return(FALSE);
  73.       sa = (BYTE *)ch->loopstart;
  74.       sl = ch->replen << 1;
  75.       sp = 0;
  76.     }
  77.   }
  78.   return(TRUE);
  79. }
  80.  
  81. void ClearPlane(UBYTE *bpl, UWORD Width, UWORD Height)
  82. {
  83.   OwnBlitter();
  84.   WaitBlit();
  85.   *(UBYTE**)0xdff054 = bpl;        // Clear the drawing area
  86.   *(UWORD*)0xdff066 = 0;
  87.   *(ULONG*)0xdff040 = 0x01000000;
  88.   *(UWORD*)0xdff058 = Height*64+Width/16;
  89.   DisownBlitter();
  90. }
  91.  
  92. int main(void)
  93. {
  94.   BYTE OldPri;
  95.   
  96.   /* Forbid multitasking while finding the port and adding the opencount */
  97.   ForbidMT();
  98.   if (hport = (struct HippoPort *)FindPort("HiP-Port"))
  99.   {
  100.     hport->opencount += 1;
  101.     PermitMT();
  102.     if (win = OpenWindowTags(NULL,
  103.         WA_Left,    100,
  104.         WA_Top,        50,
  105.         WA_Width,    320+10,
  106.         WA_Height,    64+20,
  107.         WA_Title,    "Scope for HiP!",
  108.         WA_ScreenTitle,    "Coded in C by Thomas Sköldenborg (Explorer/Three Little Elks)",
  109.         WA_Flags,    WFLG_CLOSEGADGET |
  110.                 WFLG_DRAGBAR |
  111.                 WFLG_DEPTHGADGET |
  112.                 WFLG_RMBTRAP |
  113.                 WFLG_ACTIVATE,
  114.         WA_IDCMP,    IDCMP_CLOSEWINDOW |
  115.                 IDCMP_MOUSEBUTTONS |
  116.                 IDCMP_RAWKEY,
  117.         TAG_DONE))
  118.     {
  119.       if (plane1 = AllocMem(320/8*64, MEMF_CHIP | MEMF_CLEAR))
  120.       {
  121.       if (plane2 = AllocMem(320/8*64, MEMF_CHIP | MEMF_CLEAR))
  122.       {
  123.        InitBitMap(&bmap, 1, 320, 64);
  124.        
  125.        OldPri = SetTaskPri(FindTask(NULL), -127);
  126.       
  127.         while (Going)
  128.         {
  129.           /* Wait for the top of the next video frame */
  130.           WaitTOF();
  131.           
  132.           tmp = plane1;        // Double (Triple?) Buffer
  133.           plane1 = plane2;
  134.           plane2 = tmp;
  135.           
  136.           ClearPlane(plane2, 320, 64);
  137.           
  138.           if (hport->playertype == 33)        // check if pt module
  139.           {
  140.             /* Draw all four scopes */
  141.             DrawScope (hport->PTch1, plane1, 80*0, 80, 32);
  142.             DrawScope (hport->PTch2, plane1, 80*1, 80, 32);
  143.             DrawScope (hport->PTch3, plane1, 80*2, 80, 32);
  144.             DrawScope (hport->PTch4, plane1, 80*3, 80, 32);
  145.           }
  146.           
  147.           bmap.Planes[0] = plane1;
  148.           BltBitMapRastPort(&bmap, 0, 0,
  149.                             win->RPort, 5, 12, 320, 64,
  150.                             0xc0);
  151.           
  152.           while (imsg = (struct IntuiMessage *)GetMsg(win->UserPort))
  153.           {
  154.             class = imsg->Class;
  155.             code  = imsg->Code;
  156.             ReplyMsg((struct Message *)imsg);
  157.             switch (class)
  158.             {
  159.               case IDCMP_CLOSEWINDOW:
  160.                 Going = FALSE;
  161.                 break;
  162.               case IDCMP_MOUSEBUTTONS:
  163.                 break;
  164.               case IDCMP_RAWKEY:
  165.                 switch (code)
  166.                 {
  167.                   case 0x45:        // Esc
  168.                     Going = FALSE;
  169.                     break;
  170.                 }
  171.                 break;
  172.             }
  173.           }
  174.         }
  175.        
  176.        SetTaskPri(FindTask(NULL), OldPri);
  177.       
  178.       FreeMem(plane2, 320/8*64);
  179.       } else Printf("Out of memory!\n");
  180.       FreeMem(plane1, 320/8*64);
  181.       } else Printf("Out of memory!\n");
  182.       CloseWindow(win);
  183.     } else Printf("Couldn't open window!\n");
  184.     hport->opencount -= 1;
  185.   } else Printf("Couldn't find HiP port!\n");
  186.   PermitMT();
  187.  return(0);
  188. }
  189.  
  190.